package com.tuliyou.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tuliyou.common.util.Result;
import com.tuliyou.dto.ScoreRankDTO;
import com.tuliyou.entity.ScoreRank;
import com.tuliyou.mapper.ScoreRankMapper;
import com.tuliyou.service.ScoreRankService;
import org.springframework.stereotype.Service;

@Service
public class ScoreRankServiceImpl extends ServiceImpl<ScoreRankMapper, ScoreRank> implements ScoreRankService {

    @Override
    public Result<ScoreRankDTO> getRankByScore(Integer statYear, Integer score) {
        ScoreRank scoreRank = query().eq("stat_year", statYear).eq("score", score).one();
        return Result.success(ScoreRankDTO.fromScoreRank(scoreRank));
    }

    @Override
    public Result<ScoreRankDTO> getScoreByRank(Integer statYear, Integer rank) {
        ScoreRank scoreRank = query().eq("stat_year", statYear).eq("`rank`", rank).one();
        return Result.success(ScoreRankDTO.fromScoreRank(scoreRank));
    }
}
